package L1job;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class StudentsManager {
    List<Students> student=new ArrayList<Students>();
    public void Add_Students(String number,String name,String sex){
        Students s=new Students();
        s.setName(name);
        s.setSex(sex);
        s.setNum(number);
        student.add(s);
        for (Iterator<Students> iterator = student.iterator(); iterator.hasNext(); ) {
            Students next =  iterator.next();
            System.out.println(next.getNum()+" "+next.getName()+" "+next.getSex());
        }
    }
    public void Read_Students(){
        if(student.size()!=0 && student!=null) {
            for (Iterator<Students> iterator = student.iterator(); iterator.hasNext(); ) {
                Students next = iterator.next();
                System.out.println(next.getNum() + " " + next.getName() + " " + next.getSex());
            }
        }else {
            System.out.println("没有学生数据可以查看！");
        }

    }
    public void Read_Student(String number){
        if(student.size()!=0 && student!=null){
            for (int i = 0; i < student.size(); i++) {
                Students students =  student.get(i);
                if(students.getNum().equals(number)){
                    System.out.println("学号是"+number+"的学生信息："+students.getNum()+" "+students.getName()+" "+students.getSex());
                }else {
                    System.out.println("没有该学生数据！");
                }
            }

        }else {
            System.out.println("没有学生数据可以查看！");
        }
    }
    public void Del_Students(String number){
        if(student.size()!=0 && student!=null){
            for (int i = 0; i < student.size(); i++) {
                Students students =  student.get(i);
                if(students.getNum().equals(number)){
                    student.remove(i);
                }

            }

            System.out.println("成功删除学号是"+number+"的学生信息");
        }else {
            System.out.println("没有学生数据可以删除！");
        }
    }
}
